### Include common Makefile configuration
#
include   $(top_srcdir)/build/Makefile.am.common



### Local configuration changes
#
AUTOMAKE_OPTIONS = foreign subdir-objects
ACLOCAL_AMFLAGS = -I build/m4



### Subdir processing order
#
# Process etc/ before other subdirs
#
# If Snoopy has config file enabled, then there is a small time frame
# between installation of library and subsequent installation of
# initial configuration file where ini parsing library emits an error about
# configuration file not being found. Therefore we first install
# configuration file and only then the Snoopy library itself.
#
# Also, lib/ must be processed before src/, as ini parsing library is needed
# there if config file is enabled.
#
SUBDIRS  =
if CONFIGFILE_ENABLED
SUBDIRS += etc
endif
SUBDIRS += lib
SUBDIRS += src
SUBDIRS += doc
SUBDIRS += tests



### Additional files to distribute in distribution package
#
EXTRA_DIST = \
	dev-tools/libexec/get-release-version.sh \
	README.md



### Make check aliases
#
checks: check
test:   check
tests:  check



### Enable/disable targets
#
enable: install
	$(sbindir)/snoopyctl enable

# We need to run a local instance of `snoopyctl`, as `make uninstall` first
# removes the installed `snoopyctl` instance before running the `uninstall-local` target.
disable:
	./src/cli/snoopyctl disable

# Disable it if we are uninstalling it, to avoid error messages
# about missing library that should be preloaded.
uninstall-local: disable



### Clean these files additionally
#

# Clean release files
clean-local-this-dir:
	rm -f  config.h.in~ ; \
	rm -f  config.log ; \
	rm -f  configure~ ; \
	rm -rf snoopy-[0-9].[0-9].* ; \
	rm -f  snoopy-*.tar.gz* ; \
	rm -f  snoopy-latest-*.txt ; \
	rm -rf cov-int* ; \
	rm -rf sonarcloud-build-wrapper-output ; \
	rm -rf sonar-cfamily.reproducer ; \
	rm -rf .scannerwork ; \
	rm -rf packaging/deb/.debhelper ; \
	rm -f  packaging/deb/autoreconf.after ; \
	rm -f  packaging/deb/autoreconf.before ; \
	rm -f  packaging/deb/debhelper-build-stamp ; \
	rm -f  packaging/deb/files ; \
	rm -f  packaging/deb/snoopy.debhelper.log ; \
	rm -f  packaging/deb/snoopy.postrm.debhelper ; \
	rm -f  packaging/deb/snoopy.substvars ; \
	rm -rf packaging/deb/snoopy ; \
	rm -f  ../snoopy_*_*.buildinfo ; \
	rm -f  ../snoopy_*_*.changes ; \
	rm -f  ../snoopy_*_*.deb ; \
	rm -f  ../snoopy-dbgsym_*_*.ddeb ; \
	rm -rf packaging/rpmbuild ; \
	rm -f  snoopy-*.pkg.tar.zst ; \
	true



# Clean all files that were generated by bootstrap.sh, autoscan, packaging etc.
# (anything that is not in git repository must go away)
gitclean: maintainer-clean
	rm -f  aclocal.m4 ; \
	rm -fr autom4te.cache ; \
	rm -f  autoscan.log ; \
	rm -fr build/aux/ ; \
	rm -fr build/m4/ ; \
	rm -f  config.h.in ; \
	rm -f  configure ; \
	rm -f  debian ; \
	rm -f  packaging/deb/changelog ; \
	rm -f  PKGBUILD ; \
	true



### Maintainer targets
#
#
# Bootstrap: simplify maintainer's life
#
.PHONY: bootstrap
bootstrap: maintainer-clean
	./bootstrap.sh
#
#
# Valgrind: run valgrind
#
.PHONY: valgrind
valgrind: all
	valgrind -v \
	--error-exitcode=1 \
	--track-fds=yes \
	--smc-check=all \
	--leak-check=full \
	--undef-value-errors=yes \
	--track-origins=yes \
	./tests/bin/snoopy-test run everything ;



### Code coverage
#
if CODE_COVERAGE_ENABLED

coverage-report:
	./dev-tools/libexec/generate-gcov-reports.sh

coverage: coverage-clean check coverage-report

endif
